<?php
$this->headTitle($this->translator('user_register_title'));
$this->headLink()->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.all.css');
$this->headScript()->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate/jquery.validate.min.js');

if($this->register_successful!=1){
?>

<div class="t_bizprofile_register">
    <h2><?php echo $this->translator('user_register_title'); ?></h2>
    <!--div class="flash_message"><?php echo $this->flashMessenger(); ?></div-->
    <?php if($this->user_register_success == 1):?>
    <div class="flash_message" style="text-align: center; padding: 3px 0px 3px;"><?php echo $this->translator('user_register_success'); ?></div>
    <?php endif;?>
    <form method="post" action="<?php echo $this->url(array(), 'bizprofile_user_register'); ?>" id="registerUserForm">
        <div class="clearfix">
            <label><?php echo $this->translator('user_register_fullname'); ?>:</label>
            <font style="color:red; padding-left:5px;"> (*)</font>
            <input type="text" id="full_name" name="full_name" style="width: 200px" />
        </div>

        <!--<div class="clearfix">
            <label><?php echo $this->translator('user_register_user_name'); ?>:</label>
            <input type="text" id="username" name="username" style="width: 200px" />
        </div>-->

        <div class="clearfix">
            <label><?php echo $this->translator('user_register_email'); ?>:</label>
            <font style="color:red; padding-left:5px;"> (*)</font>
            <input type="text" id="email" name="email" style="width: 200px" />
        </div>

        <div class="clearfix">
            <label><?php echo $this->translator('user_register_password'); ?>:</label>
            <font style="color:red; padding-left:5px;"> (*)</font>
            <input type="password" id="password" name="password" style="width: 200px" />
        </div>

        <div class="clearfix">
            <label><?php echo $this->translator('user_register_confirm_password'); ?>:</label>
            <input type="password" id="confirmPassword" name="confirmPassword" style="width: 200px" />
        </div>

        <div class="clearfix">
            <label><?php echo $this->translator('user_register_full_address'); ?>:</label>
            <font style="color:red; padding-left:5px;"> (*)</font>
            <input type="text" id="address" name="address" style="width: 200px" />
        </div>

        <div class="clearfix">
            <label><?php echo $this->translator('user_register_city'); ?>:</label>
            <font style="color:red; padding-left:5px;"> (*)</font>
            <input type="text" id="city" name="city" style="width: 200px" />
        </div>

        <div class="clearfix">
            <label><?php echo $this->translator('user_register_security_code'); ?>:</label>
            <!--<img src="<?php echo $this->APP_STATIC_SERVER ?>/images/captcha/<?php echo $this->captchaId ?>.png" alt="Captcha code" /><br-->            
            <div style="width:200px; height:45px; padding-left:120px;"><span id="reg_captcha"></span>&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" id="resetCaptcha">reset</a></div>
        </div>

        <div class="clearfix">
            <label><?php echo $this->translator('user_register_verify_code'); ?></label>
            <font style="color:red; padding-left:5px;"> (*)</font>
            <input name="captcha[input]" id="captchaInput" type="text" />
            <input name="captcha[id]" id="captchaId" type="hidden" value="" />
        </div>

        <div class="clearfix">
            <label>&nbsp;</label>
            <?php echo $this->tokenElement; ?>
            <button type="submit"><span><?php echo $this->translator('user_register_submit_button'); ?></span></button>
        </div>        
    </form>
</div>

<?php 
}
else 
{
?>
<div class="t_bizprofile_register">
	<h2><?php echo $this->translator('user_register_active'); ?></h2>
	<?php echo $this->text;?>
	
</div>
<?php
}
?>




<script type="text/javascript">
function captcha(){	
    jQuery.ajaxq('register', {
        type: 'POST',
        url: "<?php echo $this->url(array(), 'bizprofile_user_captcha'); ?>",
        success: function(response) {
            arrRes = response.split(';;');
            id = arrRes[0];
            word = arrRes[1];
            img = '<img src="<?php echo $this->APP_STATIC_SERVER ?>/images/captcha/'+id+'.png" alt="Captcha code" />';
            jQuery('#reg_captcha').html(img);
            jQuery('#captchaId').attr('value', id);
            jQuery('#captchaInput').attr('value', '');
        }
    });
}

$(document).ready(function() {

    /**
    *Auto load captcha
    */
    captcha();

    /**
    *Reset captcha
    */
   	$('#resetCaptcha').click(function(){
        captcha();
    });

    /**
    * Validate form
    */
    $('#registerUserForm').validate({
        rules: {
            /*username: {
                required: true,
                remote: '<?php echo $this->url(array('check_type' => 'username'), 'core_user_check'); ?>'
            },*/
            full_name: {
                required: true
            },
            email: {
                required: true,
                email: true,
                remote: '<?php echo $this->url(array('check_type' => 'email'), 'bizprofile_user_check'); ?>'
            },
            password: {
                required: true,
                minlength: 5
            },
            confirmPassword: {
                equalTo: '#password'
            },
            address: {
                required: true
            },
            city: {
                required: true
            },
            "captcha[input]": {
                required: true,                
                remote: {
			        url: '<?php echo $this->url(array('check_type' => 'captcha'), 'bizprofile_user_check'); ?>',
			        type: "post",
			        data: {
			          captchaId: function() {
			            return $("#captchaId").val();
			          }
			        }
			    }
            }
        },
        messages: {
            /*username: {
                required: "<?php echo $this->translator('user_register_username_required'); ?>",
                remote: "<?php echo $this->translator('user_register_username_exists'); ?>"
            },*/
            full_name: {
                required: "<?php echo $this->translator('user_register_fullname_required'); ?>"
            },
            email: {
                required: "<?php echo $this->translator('user_register_email_required'); ?>",
                email: "<?php echo $this->translator('user_register_email_invalid'); ?>",
                remote: "<?php echo $this->translator('user_register_email_exists'); ?>"
            },
            password: {
                required: "<?php echo $this->translator('user_register_password_required'); ?>",
                minlength: "<?php echo $this->translator('user_register_password_minlength'); ?>"
            },
            confirmPassword: {
                equalTo: "<?php echo $this->translator('user_register_password_equal'); ?>"
            },
            address: {
                required: "<?php echo $this->translator('user_register_address_required'); ?>"
            },
            city: {
                required: "<?php echo $this->translator('user_register_city_required'); ?>"
            },
            "captcha[input]": {
                required: "<?php echo $this->translator('user_register_captcha_required'); ?>",
                remote: "<?php echo $this->translator('user_register_captcha_equal'); ?>"
            }
        }
    });
});
</script>
